cc.Class({
    extends: cc.Component,

    properties: {
       itemNode: cc.Node,
       iconSpts: [cc.SpriteFrame],
       levelSpts: [cc.SpriteFrame],

        lb_bar1: cc.Label,
        lb_bar2: cc.Label,
        lb_bar3: cc.Label,
        lb_bar4: cc.Label,
        lb_bar5: cc.Label,
        lb_bar6: cc.Label,

    },

    onLoad () {
        this.container = this.itemNode.parent;
        this.itemNode.parent = null;
        for(var i = 0; i < 5; i++) this.initItem(i);

        this.initWords();
    },

    initWords: function(){
        this.lb_bar1.string = LangLocal.word25;
        this.lb_bar2.string = LangLocal.word34;
        this.lb_bar3.string = LangLocal.word36;
        this.lb_bar4.string = LangLocal.word38;
        this.lb_bar5.string = LangLocal.word37;
        this.lb_bar6.string = LangLocal.word35;
    },

    initItem(order) {
        var item = cc.instantiate(this.itemNode);
        item.parent = this.container;
        item.find('motor_icon', cc.Sprite).spriteFrame = this.iconSpts[order];
        item.find('motor_name', cc.RichText).string = '<color=#ffffff><outline color=black width=2><b>00' + (order + 1) + '</b></outline></color>';
        var energy = GLOBAL.getMotorEnergy(order);
        var items = ['zouxian', 'gonglv', 'zhidong', 'dongli', 'bizhen'];
        for(var i = 0; i < 5; i++) {
            var t = items[i];
            item.find('motor_' + t, cc.Sprite).spriteFrame = this.getEnergyIcon(energy[t]);
        }
    },

    getEnergyIcon(value)  {
        if(value < 7.5) return this.levelSpts[0];
        else if(value < 9) return this.levelSpts[1]; 
        else return this.levelSpts[2];
    }
});
